# 1.导入模块
import requests
import time

# 2.确认url
url = 'http://www.whggzy.com/front/search/category'

head = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36'
}

#3.进行翻页处理,根据观察，确认url都是一样的，所不同的是载荷中的pageNo不同,所以通过对pageNo值的修改进行翻页处理
for page in range(1,6):
    zaihe ={
        "utm":"sites_group_front.620b2ed1.0.0.36c1315037f511ee9cc615a0e772a749",
        "categoryCode":"WorkDynamics",
        "pageSize":15,
        "pageNo":page
    }

    #在请求响应中Content-Type:application/json需要json数据所以用requests方法中的json,如果想要用data,需要通过loads将data转换为json数据格式再使用
    res = requests.post(url, headers=head, json=zaihe)

    #获取数据
    data = res.json()['hits']['hits']

    #提取数据
    for i in data:
        title = i['_source']['title']
        publicTime = i['_source']['publishDate']
        date = time.localtime(publicTime/1000)
        publicTime = time.strftime("%Y-%m-%d %H:%M:%S",date)
        print(title,publicTime)